﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SalePartial.IDAL;
using System.Data.SqlClient;
using SalePartial.Utility;
using System.Data;
using SalePartial.Model;

namespace SalePartial.SQLServerDAL
{
    public  class XPInquiry : IXPInquiry 
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int Delete(Guid InquiryID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiryDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int DeleteByAddressID(Guid AddressID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesDeleteByAddressID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int DeleteByCompanyID(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesDeleteByCompanyID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int DeleteByUserID(Guid UserID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesDeleteByUserID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public  int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPInquiryInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("InquiryID", info.InquiryID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("InquiryType", info.InquiryType),
			new SqlParameter("InquiryStatus", info.InquiryStatus),
			new SqlParameter("PartName", info.PartName),
			new SqlParameter("PartNumber", info.PartNumber),
			new SqlParameter("PartModelName",info. PartModelName),
			new SqlParameter("PartModelFile", info.PartModelFile),
			new SqlParameter("PartMaterial", info.PartMaterial),
			new SqlParameter("PartDescription", info.PartDescription),
			new SqlParameter("Quantity1", info.Quantity1),
			new SqlParameter("Quantity2", info.Quantity2),
			new SqlParameter("Quantity3", info.Quantity3),
			new SqlParameter("Unit", info.Unit),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("DeleteDate", info.DeleteDate),
			new SqlParameter("CloseDate", info.CloseDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("SubmitDate", info.SubmitDate),
			new SqlParameter("ModerationDate", info.ModerationDate),
			new SqlParameter("ModerationUserID", info.ModerationUserID),
			new SqlParameter("ExpireDate", info.ExpireDate),
			new SqlParameter("AssignDate", info.AssignDate),
			new SqlParameter("DeliveryDate", info.DeliveryDate),
			new SqlParameter("PrepaidAmount", info.PrepaidAmount),
			new SqlParameter("PaymentMethod", info.PaymentMethod),
			new SqlParameter("Currency", info.Currency),
			new SqlParameter("Delivery", info.Delivery),
			new SqlParameter("AddressID", info.AddressID),
			new SqlParameter("DeliveryComment", info.DeliveryComment),
			new SqlParameter("PurchaseVolum",info.PurchaseVolum),
			new SqlParameter("RefPrice", info.RefPrice),
			new SqlParameter("PurchasePurpose", info.PurchasePurpose),
			new SqlParameter("PartWhereUsed", info.PartWhereUsed),
			new SqlParameter("PartPicture",info. PartPicture),
			new SqlParameter("PartThumbnail", info.PartThumbnail),
			new SqlParameter("RefAttachment", info.RefAttachment),
			new SqlParameter("RefAtchComment", info.RefAtchComment),
			new SqlParameter("IsPublic", info.IsPublic)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiryInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectAll]", parameters, "XPInquiry_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectByAddressID(Guid AddressID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByAddressID]", parameters, "XPInquiry_ByAddressID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByCompanyID]", parameters, "XPInquiry_ByCompanyID");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByUserID]", parameters, "XPInquiry_ByUserID");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public  DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectDynamic]", parameters, "XPInquiry_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public  DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectPaged]", parameters, "XPInquiry_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReader(Guid InquiryID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquirySelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReaderByAddressID(Guid AddressID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("AddressID", AddressID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByAddressID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByCompanyID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  SqlDataReader SelectReaderByUserID(Guid UserID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("UserID", UserID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiriesSelectByUserID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectSingle(Guid InquiryID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("InquiryID", InquiryID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPInquirySelect]", parameters, "XPInquiry_Single");
            DataTable dt = ds.Tables["XPInquiry_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPInquiryInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("InquiryID", info.InquiryID),
			new SqlParameter("UserID", info.UserID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("InquiryType", info.InquiryType),
			new SqlParameter("InquiryStatus", info.InquiryStatus),
			new SqlParameter("PartName", info.PartName),
			new SqlParameter("PartNumber", info.PartNumber),
			new SqlParameter("PartModelName", info.PartModelName),
			new SqlParameter("PartModelFile", info.PartModelFile),
			new SqlParameter("PartMaterial", info.PartMaterial),
			new SqlParameter("PartDescription", info.PartDescription),
			new SqlParameter("Quantity1", info.Quantity1),
			new SqlParameter("Quantity2", info.Quantity2),
			new SqlParameter("Quantity3", info.Quantity3),
			new SqlParameter("Unit", info.Unit),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("DeleteDate", info.DeleteDate),
			new SqlParameter("CloseDate", info.CloseDate),
			new SqlParameter("LastSaveDate", info.LastSaveDate),
			new SqlParameter("SubmitDate", info.SubmitDate),
			new SqlParameter("ModerationDate", info.ModerationDate),
			new SqlParameter("ModerationUserID", info.ModerationUserID),
			new SqlParameter("ExpireDate", info.ExpireDate),
			new SqlParameter("AssignDate", info.AssignDate),
			new SqlParameter("DeliveryDate", info.DeliveryDate),
			new SqlParameter("PrepaidAmount",info. PrepaidAmount),
			new SqlParameter("PaymentMethod", info.PaymentMethod),
			new SqlParameter("Currency", info.Currency),
			new SqlParameter("Delivery", info.Delivery),
			new SqlParameter("AddressID", info.AddressID),
			new SqlParameter("DeliveryComment", info.DeliveryComment),
			new SqlParameter("PurchaseVolum", info.PurchaseVolum),
			new SqlParameter("RefPrice", info.RefPrice),
			new SqlParameter("PurchasePurpose",info. PurchasePurpose),
			new SqlParameter("PartWhereUsed", info.PartWhereUsed),
			new SqlParameter("PartPicture", info.PartPicture),
			new SqlParameter("PartThumbnail", info.PartThumbnail),
			new SqlParameter("RefAttachment", info.RefAttachment),
			new SqlParameter("RefAtchComment", info.RefAtchComment),
			new SqlParameter("IsPublic", info.IsPublic)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPInquiryUpdate]", parameters, RowsAffected);
        }


    }
}
